package com.carleasoft.mps.cms.business.write.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.write.bean.entity.LeadingCadreEntity;
import com.carleasoft.mps.cms.business.write.bean.po.AppointPo;
import com.carleasoft.mps.cms.business.write.bean.po.LeadingCadrePagePo;
import com.carleasoft.mps.cms.business.write.service.LeadingAppointService;
import com.carleasoft.mps.cms.business.write.service.LeadingCadreService;
import com.carleasoft.mps.cms.business.write.service.LeadingViewService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/webLeading")
public class WebController {

    @Autowired
    private LeadingCadreService leadingCadreService;
    @Autowired
    private LeadingAppointService leadingAppointService;

    /**
     * 首长指定回信人员
     *
     * @param appointPo
     * @return
     */
    @PostMapping("/appoint")
    public R appoint(@RequestBody AppointPo appointPo) {
        IBeanUtil.paramVerify(appointPo, "writeCode", "userCodes");
        boolean isOk = leadingAppointService.appoint(appointPo);
        return R.ok(isOk);
    }

    /**
     * 后台-分页 写信
     * @param leadingCadrePagePo
     * @return
     */
    @PostMapping("/pageQueryWeb")
    public R pageQueryWeb(@RequestBody LeadingCadrePagePo leadingCadrePagePo) {
        Page<LeadingCadreEntity> leadingCadreEntityPage = leadingCadreService.pageQueryWeb(new Page(leadingCadrePagePo.getCurrent(),leadingCadrePagePo.getSize()),leadingCadrePagePo);
        return R.ok(leadingCadreEntityPage);
    }


    @PostMapping("/delete")
    public R delete(@RequestBody LeadingCadreEntity leadingCadreEntity){
        IBeanUtil.paramVerify(leadingCadreEntity,"writeCode");
        boolean isOK= leadingCadreService.delete(leadingCadreEntity.getWriteCode());
        return R.ok(isOK);
    }
}
